package com.hanhanxiaochong.zhongxiangchuanmei.view.my.act;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.InviteBean;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.InviteSecondBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.HttpPostService;
import com.hanhanxiaochong.zhongxiangchuanmei.view.base.BaseActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.my.adapter.InviteSecondAdapter;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseObserver;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.ResponseBase;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * 我的邀请二级页面
 */
public class InviteSecondActivity extends BaseActivity {

    @BindView(R.id.img_left)
    ImageView imgLeft;
    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.rv_second_invite)
    RecyclerView rvSecondInvite;

    public static Intent createIntent(Context context, String uid) {
        Intent intent = new Intent(context, InviteSecondActivity.class);
        intent.putExtra("uid", uid);
        return intent;
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_invite_second);
    }

    @Override
    protected void initPresenter() {

    }

    private void setTopView() {
        imgLeft.setImageResource(R.mipmap.icon_close_black);
        txtTitle.setText("信息");
    }

    @Override
    protected void init() {
        setTopView();
        String uid = getIntent().getStringExtra("uid");

        RetrofitSource.createApi(HttpPostService.class).invitation_two(uid)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<InviteSecondBean>>(this) {
                    @Override
                    public void onSuccess(ResponseBase<InviteSecondBean> response) {
                        List<InviteBean.ListBean> list = new ArrayList<>();
                        InviteSecondBean data = response.getData();
                        InviteBean.ListBean user = data.getUser();
                        user.setUser(true);
                        list.add(user);
                        for (InviteBean.ListBean bean : data.getList()) {
                            bean.setUser(false);
                            list.add(bean);
                        }
                        InviteSecondAdapter inviteSecondAdapter = new InviteSecondAdapter(InviteSecondActivity.this, list);
                        rvSecondInvite.setLayoutManager(new LinearLayoutManager(InviteSecondActivity.this));
                        rvSecondInvite.setAdapter(inviteSecondAdapter);
                    }
                });

    }

    @OnClick({R.id.ll_leftview})
    public void onViewClicked(View view) {
        finish();
    }
}
